package com.example.administrator.text.Framgnet;

import android.annotation.TargetApi;
import android.app.Fragment;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.example.administrator.text.ModifyInformationActivity;
import com.example.administrator.text.R;
import com.example.administrator.text.WeInformation1Activity;
import com.nostra13.universalimageloader.core.ImageLoader;
import org.apache.log4j.Logger;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import app.MyApplication;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import data.SharedPreferencesUtils;
import util.AgentIp;
import util.BitmapUtil;
import util.GreenTreeNetworkUtil;
import util.HomeUtil;
import util.JumpActivityUtils;
import util.LogUtil;
import util.NetUtils;
import util.NetWorkstateUtil;
import util.RequestDataCallback;
import util.StringUtil;
import util.Url;
import view.RoundImageView;
import view.ViewLinearLayout;
import view.diaLogView.CrowdRetunDialog;
import view.diaLogView.UploadDialog;
import view.diaLogView.UploadLogDialog;
import static data.SharedPreferencesUtils.getParam;

/**
 *我的相关信息
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class We1Fragment extends Fragment{

    private UploadDialog mUploadDialog;
    private String mId,mToken;
    private String mFwq;
    private int mVip,mTime; //会员状态
    private String mWevVip = "";
    private boolean mAgainState = true; //是否需要重新登录
    private Logger mLogger = Logger.getLogger(We1Fragment.class);

    @Bind(R.id.fragment_we1_head)         RoundImageView mRVHead;  //头像
    @Bind(R.id.fragment_we1_vip)          RoundImageView mRVVip;  //vip标识
    @Bind(R.id.fragment_we1_tv_nickname)  TextView mTVNickname;  //昵称
    @Bind(R.id.fragment_we1_tv_deposit)   TextView mTVDeposit;      //会员押金
    @Bind(R.id.fragment_we1_lv_when)      TextView mTVWhen;        //上网的总时间
    @Bind(R.id.fragment_we1_tv_dissconut) TextView mTVDissconut;  //卡券数
    @Bind(R.id.fragment_we1_tv_deposit1)  TextView mTVDeposit1;      //会员押金
    @Bind(R.id.fragment_we1_lv_when1)     TextView mTVWhen1;        //上网的总时间
    @Bind(R.id.fragment_we1_tv_dissconut1)TextView mTVDissconut1;  //卡券数
    @Bind(R.id.fragment_we1_ll)           LinearLayout mLinearLayout1;             //会员押金的相关的显示
    @Bind(R.id.fragment_we1_button_ll)    LinearLayout mLinearLayout;
    @Bind(R.id.fragment_we1_account)      ViewLinearLayout mViewLLayout1;        //第一个View
    @Bind(R.id.fragment_we1_whitelist)    ViewLinearLayout mVLWhitelist;        //第一个白名单的View
    @Bind(R.id.fragment_we1_weaccount)    ViewLinearLayout mVLWeaccount;       //第一个我的时长
    @Bind(R.id.fragment_we1_account_center) ViewLinearLayout mVLAccountCenter;  //第一个账号中心
    @Bind(R.id.fragment_we1_equipment)    ViewLinearLayout mVLEquipment;      //VIEW 设备管理
    @Bind(R.id.fragment_we1_view_account) View mViewAccountCenter;             //第一个阴影的View
    @Bind(R.id.fragment_we_view_equipment)View mViewEquipment;                //设备管理阴影的View
    @Bind(R.id.fragment_we1_view1)        View mView1;                       //第一个阴影的View
    @Bind(R.id.fragment_we_view_account)  View mViewAccount;                //时长下面的View
    @Bind(R.id.fragment_we1_whitelist_view)View mViewWhitelist;            //第一个白名单的阴影View

    public We1Fragment() {

    }

    public static We1Fragment newInstance() {
        We1Fragment fragment = new We1Fragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment1_we, container, false);
        ButterKnife.bind(this,view);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        EventBus.getDefault().register(this);
        initView();
    }


    /**
     * 头像
     */
    @OnClick(R.id.fragment_we1_head)
    void head(){
        Intent intent = new Intent(getActivity(), WeInformation1Activity.class);
        startActivityForResult(intent,1);
    }

    /**
     * 头像
     */
    @OnClick(R.id.frame_head)
    void frameHead(){
        Intent intent = new Intent(getActivity(), WeInformation1Activity.class);
        startActivityForResult(intent,1);
    }

    /**
     * 会员押金 高级模式才显示
     */
    @OnClick(R.id.fragment_we1_ll_deposit)
    void deposit(){
        if(mVip !=1 ){
            JumpActivityUtils.getInstance().jumpWebView(getActivity(),Url.mATIAIRIP + Url.getUrlNew().vipdePosit+"?userid="+mId+"&vipid="+mWevVip+"&pattern="+MyApplication.getApp().getmPattern()+"&appType=1","会员购买");
        }else {
                String url = Url.mATIAIRIP +Url.getUrlNew().vipmySelf+"?userid="+mId+"&vipid="+mWevVip+"&pattern="+MyApplication.getApp().getmPattern()+"&appType=1";
                JumpActivityUtils.getInstance().jumpWebView(getActivity(),url,"会员");
        }
    }

    /**
     *  设备管理
     */
    @OnClick(R.id.fragment_we1_equipment)
    void equipment(){
        JumpActivityUtils.getInstance().jumpApiCloud5(getActivity(),0,mId,mToken,"");
    }

    /**
     *  我的时长  高级模式才显示
     */
    @OnClick(R.id.fragment_we1_ll_when)
    void when(){
        JumpActivityUtils.getInstance().jumpWeTime(getActivity());
    }

    /**
     *  账号中心
     */
    @OnClick(R.id.fragment_we1_account_center)
    void accountCenter(){
        JumpActivityUtils.getInstance().jumpWeWiFiAccount(getActivity(),"");
    }

    /**
     *  我的时长  普通模式才显示
     */
    @OnClick(R.id.fragment_we1_weaccount)
    void when1(){
        JumpActivityUtils.getInstance().jumpWeTime(getActivity());
    }

    /**
     * 联系我们
     */
    @OnClick(R.id.fragment_we1_customer)
    void customer(){
     JumpActivityUtils.getInstance().jumpReport(getActivity());
    }

    /**
     * 卡券
     */
    @OnClick(R.id.fragment_we1_ll_discount)
    void discount(){
        LogUtil.eE("discount",".........................."+MyApplication.getApp().getmPattern()+"");
        JumpActivityUtils.getInstance().jumpVoucher(getActivity());

    }

    /**
     * 提交日志
     */
    @OnClick(R.id.fragment_we1_log)
    void log(){
        getLog();
    }

    /**
     * 时长充值
     */
    @OnClick(R.id.fragment_we1_account)
    void account(){
        ArrayList list = (ArrayList) SharedPreferencesUtils.getParam(getActivity(),HomeUtil.mAppPatternArray,"list");
        int pattern = (int)list.get(0);
        if(list.size() == 2){
            pattern = (int)list.get(1);
        }
        switch (StringUtil.getStringUtilNew().judgeUIType(pattern)){
            case 1:
                if(mVip == 0){
                    Toast.makeText(getActivity(),"您现在还不是会员，请先加入会员",Toast.LENGTH_SHORT).show();
                    JumpActivityUtils.getInstance().jumpWebView(getActivity(),Url.mATIAIRIP + Url.getUrlNew().vipdePosit+"?userid="+mId+"&vipid="+mWevVip+"&pattern="+pattern,"会员购买");
                }else {
                    JumpActivityUtils.getInstance().jumpTimeRecharge(getActivity(),mWevVip);
                }
                break;
            case 2:
                if((boolean) SharedPreferencesUtils.getParam(getActivity(),HomeUtil.mVIPSTATE,true)){
                    String url = Url.mATIAIRIP +Url.getUrlNew().vipmySelf+"?userid="+mId+"&vipid="+mWevVip+"&pattern="+pattern;
                    JumpActivityUtils.getInstance().jumpWebView(getActivity(),url,"套餐");

                }else {
                    String url = Url.mATIAIRIP +Url.getUrlNew().vipdePosit+"?userid="+mId+"&vipid="+mWevVip+"&pattern="+pattern;
                    JumpActivityUtils.getInstance().jumpWebView(getActivity(),url,"套餐购买");

                }
                break;
            case 4:
                JumpActivityUtils.getInstance().jumpWeWiFiAccount(getActivity(),"");
                break;
            case 0:
                if(MyApplication.getApp().getSiteAreaid() == 2){
                    JumpActivityUtils.getInstance().jumpWeWiFiAccount(getActivity(),"");
                }else {
                    if(mViewLLayout1.getViewString().equals("会员押金")){
                        String url = Url.mATIAIRIP +Url.getUrlNew().vipmySelf+"?userid="+mId+"&vipid="+mWevVip+"&pattern="+MyApplication.getApp().getmPattern()+"&appType=1";
                        JumpActivityUtils.getInstance().jumpWebView(getActivity(),url,"会员");
                    }else {
                        Toast.makeText(getActivity(),"本区域不支持次功能",Toast.LENGTH_SHORT).show();
                    }
                }
                break;
        }
    }

    /**
     * 故障上报
     */
    @OnClick(R.id.fragment_we1_fault)
    void fault(){
        JumpActivityUtils.getInstance().jumpApiCloud2(getActivity(),mId);
    }

    /**
     * 上网明细
     */
    @OnClick(R.id.fragment_we1_journal)
    void journal(){
        LogUtil.eE("","联网成功后的ip..."+ MyApplication.getApp().getFWQString());
        JumpActivityUtils.getInstance().jumpApiCloud1(getActivity(),mId,mToken);

    }

    /**
     * 设置
     */
    @OnClick(R.id.fragment_we1_set)
    void we1Set(){
      JumpActivityUtils.getInstance().jumpSetNetFi(getActivity());
       // JumpActivityUtils.getInstance().jumpApiCloud4(getActivity());
    }

    /**
     * 白名单管理
     */
    @OnClick(R.id.fragment_we1_whitelist)
    void whiteList(){

        if(mUploadDialog == null){
            mUploadDialog = new UploadDialog(getActivity(),"连接中");
            mUploadDialog.show();
        }else {
            mUploadDialog.getStringShow("连接中");
            mUploadDialog.show();
        }

        AgentIp.newInstance(getActivity()).setNetWorkstate2(new AgentIp.OnNetworkStateClickListener() {
            @Override
            public void onClick(boolean state) {
                mUploadDialog.dismiss();
                if(state){
                    JumpActivityUtils.getInstance().jumpApiCloud(getActivity(),mId);
                }else {
                    Toast.makeText(getActivity(), "请先连接网络", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    /**
     * 更新时长
     */
    public void showBalance(){
        int pattern = StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern());
        if(pattern == 1){
            queryBalance();
        }
    }

    /**
     * 加载View
     */
    private void initView() {
        mId = (String) SharedPreferencesUtils.getParam(getActivity(), HomeUtil.mUseridDB,"");
        mToken = (String) SharedPreferencesUtils.getParam(getActivity(), HomeUtil.mTokenDB, "");
        setHead();
        String nicKname = (String) SharedPreferencesUtils.getParam(getActivity(), ModifyInformationActivity.NICKNAME,"");   //昵称
        mTVNickname.setText(nicKname);
        mWevVip = (int) SharedPreferencesUtils.getParam(getActivity(), HomeUtil.mVIPCombonum,1)+"";
        setView();
        getWhitelis();
    }

    /**
     * 设置View
     */
    public void setView(){
        int pattern1 = MyApplication.getApp().getmPattern();
        ArrayList list = (ArrayList) SharedPreferencesUtils.getParam(getActivity(),HomeUtil.mAppPatternArray,"list");
        LogUtil.eE("pattern",".....pattern1...."+pattern1);
        if(list.size() == 1 || (boolean) getParam(getActivity(),HomeUtil.mVIPSTATE,true)){
            if(StringUtil.getStringUtilNew().judgeUIType(pattern1) != 0){
                setView1(pattern1);
            }else {
                if(MyApplication.getApp().getSiteAreaid() == 1){
                    mVLWeaccount.setVisibility(View.GONE);
                    mViewLLayout1.setVisibility(View.GONE);
                    mView1.setVisibility(View.GONE);
                    mVLWeaccount.setVisibility(View.GONE);
                    mLinearLayout.setVisibility(View.VISIBLE);
                    mViewAccount.setVisibility(View.GONE);
                }else if(MyApplication.getApp().getSiteAreaid() == 2){
                    mVLWeaccount.setVisibility(View.GONE);
                    mViewAccount.setVisibility(View.GONE);
                    mLinearLayout.setVisibility(View.VISIBLE);
                    mViewLLayout1.setVisibility(View.VISIBLE);
                    mViewLLayout1.setViewText("账号中心");
                }else if(MyApplication.getApp().getSiteAreaid() == 0){
                    mVLWeaccount.setVisibility(View.GONE);
                    mViewLLayout1.setVisibility(View.GONE);
                    mView1.setVisibility(View.GONE);
                    mVLWeaccount.setVisibility(View.GONE);
                    mLinearLayout.setVisibility(View.VISIBLE);
                    mViewAccount.setVisibility(View.GONE);
                    queryVip(1);
                }else {
                    mViewLLayout1.setVisibility(View.VISIBLE);
                    mViewLLayout1.setViewText("时长充值");
                    mViewLLayout1.setIVBitmp(R.mipmap.recharge);
                }
            }
        }else {
            mView1.setVisibility(View.GONE);
            mViewAccount.setVisibility(View.GONE);
        }
    }

    private void setView1(int pattern1){
        if(StringUtil.getStringUtilNew().judgeUIType(pattern1) == 2){
            mViewLLayout1.setVisibility(View.VISIBLE);
            mVLWeaccount.setVisibility(View.GONE);
            mViewAccount.setVisibility(View.GONE);
            mViewLLayout1.setViewText("我的套餐");
            mViewLLayout1.setIVBitmp(R.mipmap.we_package);
            mVLEquipment.setVisibility(View.VISIBLE);
            mViewEquipment.setVisibility(View.VISIBLE);
        }else if(StringUtil.getStringUtilNew().judgeUIType(pattern1) == 1){
            mLinearLayout1.setVisibility(View.VISIBLE);
            if(mLinearLayout !=null){
                mLinearLayout.setVisibility(View.VISIBLE);
            }
            queryBalance();
            queryVip(0);
            mVLWeaccount.setVisibility(View.GONE);
            mViewAccount.setVisibility(View.GONE);
            mView1.setVisibility(View.VISIBLE);
            mViewLLayout1.setVisibility(View.VISIBLE);
        }else if(StringUtil.getStringUtilNew().judgeUIType(pattern1) == 4){
            mVLWeaccount.setVisibility(View.GONE);
            mViewAccount.setVisibility(View.GONE);
            mLinearLayout.setVisibility(View.VISIBLE);
            mViewLLayout1.setVisibility(View.VISIBLE);
            mViewLLayout1.setViewText("账号中心");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        EventBus.getDefault().unregister(this);
        if(mUploadDialog !=null){
            mUploadDialog.dismiss();
        }
    }

    /**
     * 查询时长
     */
    private void queryBalance(){
        if((boolean)SharedPreferencesUtils.getParam(getActivity(),HomeUtil.AppAgainState,true)){
            if(MyApplication.getApp().getSiteAreaid() == 0){
                mAgainState = false;
            }
        }
        String url = "";
        HashMap mMap = new HashMap<>();
        mMap.put("userid",mId);
        String stringJson = StringUtil.getStringUtilNew().hashMapToJson(mMap); //参数包
        long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.mStirngpcDeal_selectBalance,stringJson,mToken,mId,time);
        Map map = StringUtil.getStringUtilNew().getMapNew(getActivity(),stringJson,mToken,mId, Url.mStirngpcDeal_selectBalance,stirngSign,time);
        if(NetUtils.getInstance(getActivity()).getNetWorkTeyt()  == 0){
            url = Url.getUrlNew().getAppIP();
        }else {
            url = MyApplication.getApp().getFWQString();
        }
        LogUtil.eE("fwq","  "+url);
        mLogger.info("queryBalance()--->查询时长--fwq"+url+"stirngSign"+stirngSign);
        GreenTreeNetworkUtil.getInstance().doPost(getActivity(),url,1,map,new RequestDataCallback() {
            @Override public void onSuccess(String response) {
                try {
                    mLogger.info("queryBalance()--->onSuccess--String"+response);
                    JSONObject jsonObject = new JSONObject(response);
                    String code = jsonObject.getString("code");
                    if(code.equals("1")){
                        int time = (jsonObject.getInt("longTime")/60);
                        int t = (jsonObject.getInt("longTime")%60);

                        if(time <= 9){
                            if(time>0){
                                if(t<=9){
                                    mTVWhen.setText("0"+time+":0"+t);
                                }else {
                                    mTVWhen.setText("0"+time+":"+t);
                                }
                            }else {
                                mTVWhen.setText(time+"");
                            }
                        }else {
                            if(t<=9){
                                mTVWhen.setText(time+":0"+t);
                            }else {
                                mTVWhen.setText(time+":"+t);
                            }
                        }
                        SharedPreferencesUtils.setParam(getActivity(),HomeUtil.mVIPTime,jsonObject.getInt("longTime"));
                        int tichetNum = jsonObject.getInt("ticketNum");
                        if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 1){
                            mTVDissconut.setText(tichetNum+"");
                        }
                    }else if (code.equals("-2")){
                        if(mAgainState){
                            CrowdRetunDialog crowdRetunDialog = new CrowdRetunDialog(getActivity());
                            crowdRetunDialog.show();
                        }
                    }else {
                        mTVWhen.setText("- -");
                        mTVDissconut.setText("- -");
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                    mTVWhen.setText("- -");
                    mTVDissconut.setText("- -");
                }
            }

            @Override public void onFailure(Throwable error) {
                mTVWhen.setText("- -");
                mTVDissconut.setText("- -");
            }
        });
    }

    /**
     * 查询VIP
     */
    private void queryVip(final int type){
        if((boolean)SharedPreferencesUtils.getParam(getActivity(),HomeUtil.AppAgainState,true)){
            if(MyApplication.getApp().getSiteAreaid() == 0){
                mAgainState = false;
            }
        }
        String url = "";
        HashMap map = new HashMap<>();
        map.put("userid",mId);
        String stringJson = StringUtil.getStringUtilNew().hashMapToJson(map); //参数包
        long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.mStirngpcDeal_selectVipmember,stringJson,mToken,mId,time);
        Map map1 = StringUtil.getStringUtilNew().getMapNew(getActivity(),stringJson,mToken,mId, Url.mStirngpcDeal_selectVipmember,stirngSign,time);
        if(NetUtils.getInstance(getActivity()).getNetWorkTeyt() == 0){
            url = Url.getUrlNew().getAppIP();
        }else {
            url = MyApplication.getApp().getFWQString();
        }
        LogUtil.eE("fwq","  "+url);
       mLogger.info("queryVip()--->查询VIP--fwq"+url+"stirngSign"+stirngSign);
        GreenTreeNetworkUtil.getInstance().doPost(getActivity(),url,1,map1,new RequestDataCallback() {
            @Override public void onSuccess(String response) {
                try {
                   mLogger.info("queryVip()--->onSuccess--String"+response);
                    JSONObject jsonObject = new JSONObject(response);
                    String code = jsonObject.getString("code");
                    if (code.equals("1")) {
                        mVip = 1;
                        mRVVip.setVisibility(View.VISIBLE);
                        mTVDeposit.setText("¥"+jsonObject.getString("pledge"));
                        mRVVip.setVisibility(View.VISIBLE);
                        if(type == 1){
                            mLinearLayout.setVisibility(View.VISIBLE);
                            mViewLLayout1.setVisibility(View.VISIBLE);
                            mViewLLayout1.setViewText("会员押金");
                            mView1.setVisibility(View.VISIBLE);
                            mWevVip = jsonObject.getInt("goodsid")+"";
                        }
                    } else if (code.equals("-2")) {
                        if(mAgainState){
                            CrowdRetunDialog crowdRetunDialog = new CrowdRetunDialog(getActivity());
                            crowdRetunDialog.show();
                        }
                    } else{
                        mVip = 0;
                        mRVVip.setVisibility(View.GONE);
                        mTVDeposit.setText("0");
                    }

                } catch (Exception e) {e.printStackTrace();
                    mVip = 0;
                    mRVVip.setVisibility(View.GONE);
                    mTVDeposit.setText("- -");}
            }

            @Override public void onFailure(Throwable error) {
                mTVDeposit.setText("- -");
            }
        });
    }

    /**
     * 查看白名单的权限
     */
    public void getWhitelis(){
        String url = Url.getUrlNew().Whitelist+"?userid="+mId;
        mLogger.info("...getWhitelist...白名单权限.....url"+url);
        GreenTreeNetworkUtil.getInstance().doGet(url, null, new RequestDataCallback() {
            @Override public void onSuccess(String response) {
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    if(jsonObject.getInt("code") == 1){
                        mLogger.info("...getWhitelist...白名单权限。。。response"+response);
                        if(mVLWhitelist !=null && mViewWhitelist !=null){
                            mVLWhitelist.setVisibility(View.VISIBLE);
                            mViewWhitelist.setVisibility(View.VISIBLE);
                        }
                    }
                } catch (JSONException e) {e.printStackTrace();}
            }

            @Override public void onFailure(Throwable error) {
                mLogger.info("...getWhitelist...白名单权限。。。error"+error);
            }
        });
    }

    /**
     * 设置头像
     */
    private void setHead(){
        final String headUrl = (String) SharedPreferencesUtils.getParam(getActivity(), ModifyInformationActivity.WEHEAD,"");      //头像地址
        if(Url.getUrlNew().getWE_PORTRAIT().equals("")){
            AgentIp.newInstance(getActivity()).setNetWorkstate2(new AgentIp.OnNetworkStateClickListener() {
                @Override
                public void onClick(boolean state) {
                    if(state){
                        ImageLoader mImageLoader = MyApplication.getApp().getImageLoader();
                        mImageLoader.displayImage(headUrl, mRVHead, HomeUtil.getHemeUtilNew().getDisplayImageOptions(true, R.mipmap.weaccount_head));
                    }else {
                        BitmapUtil.newBitmap().showBitmap(getActivity(),headUrl,mRVHead, R.mipmap.weaccount_head,null);
                    }
                }
            });

        }else {
            Bitmap bitmap = BitmapFactory.decodeFile(Url.getUrlNew().getWE_PORTRAIT());
            mRVHead.setImageBitmap(bitmap);
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        LogUtil.eE("","onActivityResult");
        if (resultCode != getActivity().RESULT_OK) {
            return;
        }
        initView();
    }

    /**
     * 提交日志
     */
    private void getLog(){
        mFwq = (String) getParam(getActivity(),HomeUtil.mFWQ,"");
        if(mFwq.equals("")){
            mFwq = MyApplication.getApp().getFWQString();
        }
        if(MyApplication.getApp().getSiteAreaid() >=10000){
            final UploadDialog uploadDialog = new UploadDialog(getActivity(),"连接中");
            uploadDialog.show();
            HomeUtil.getHemeUtilNew().domainUtil(getActivity(),2000,new HomeUtil.OnHomeUtilClickListener() {
                @Override
                public void onItemClick(String type) {
                    if(type.equals("no")){
                        NetWorkstateUtil.getInstance().showNetworking(getActivity(), new NetWorkstateUtil.NetworkingOnClickListener() {
                            @Override
                            public void onItemClick(boolean state) {
                                uploadDialog.dismiss();
                                if(state){
                                    Url.getUrlNew().setNETWORKING_ATATE(1);
                                }
                                UploadLogDialog noNetDialog = new UploadLogDialog(getActivity(),StringUtil.getStringUtilNew().uploadHead(mFwq));
                                noNetDialog.show();
                            }
                        });
                    }else {
                        uploadDialog.dismiss();
                        final String url = StringUtil.getStringUtilNew().uploadHead(MyApplication.getApp().getFWQString());
                        UploadLogDialog noNetDialog = new UploadLogDialog(getActivity(),url);
                        noNetDialog.show();
                    }
                }
            });
        }else {
            final String url = StringUtil.getStringUtilNew().uploadHead(MyApplication.getApp().getFWQString());
            UploadLogDialog noNetDialog = new UploadLogDialog(getActivity(),url);
            noNetDialog.show();
        }
    }

    /*** 订阅事件FirstEvent*/
    @Subscribe
    public void onEventMainThread(final String string){
        LogUtil.eE("","onEventMainThread......."+string);
        if(string !=null && !string.equals("")){
            if(string.equals("vip")){
                if(StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern()) == 1){
                    queryVip(0);
                }
                if(MyApplication.getApp().getSiteAreaid() >=10000 || MyApplication.getApp().getSiteAreaid() == 0){
                    HomeUtil.getHemeUtilNew().saveCombo(getActivity(),0,null);
                    updateView();
                }
            }else if(string.equals("balance")){
                queryBalance();
            }else if(string.equals("update_head")){
                setHead();
            }else if(string.equals("shut_network")){
                if(Url.getUrlNew().getNETWORKING_ATATE() == 1){
                    NetWorkstateUtil.getInstance().getBrokenNetwork(getActivity(),null,1);
                    Url.getUrlNew().setIsonResumeJudge(false);
                }
            }else if(string.equals("wifl_view")){
                setView();
            }
        }
    }

    /**
     * 更新view
     */
    private void updateView(){
        HomeUtil.getHemeUtilNew().getHandlerNew().postDelayed(new Runnable() {
            @Override
            public void run() {
                setView();
            }
        },2000);
    }

}
